package com.chat.simplechat.websocket;

import com.chat.simplechat.interceptor.WebSocketInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.annotation.Resource;

/**
 * websocket配置
 * @author wangyabin
 * @date 2022/10/28 17:35
 */
@Configuration
@EnableWebSocket
public class SpringWebSocketConfig implements WebSocketConfigurer {
    
    @Resource
    private SpringWebSocket springWebSocket;
    
    @Resource
    private WebSocketInterceptor webSocketInterceptor;
    
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(springWebSocket,"spring/websocket")
                .addInterceptors(webSocketInterceptor)
                .setAllowedOrigins("*");
    }
}
